import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.exceptions.DeserializationException;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.FilterBase;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

/**
 * Created by spark on 16-10-16.
 */
public class CustomerFilter extends FilterBase{

    private byte[] value = null;
    private boolean filterRow = true;

    public CustomerFilter() {
        super();
    }

    public CustomerFilter(byte[] value) {
        this.value = value;
    }

    @Override
    public void reset() throws IOException {
        filterRow = true;
    }

    @Override
    public boolean filterRow() throws IOException {
        return filterRow;
    }

    @Override
    public ReturnCode filterKeyValue(Cell v) throws IOException {
        if (Bytes.compareTo(value, CellUtil.cloneValue(v)) == 0) {
            filterRow = false;
        }

        return ReturnCode.INCLUDE;
    }

    @Override
    public byte[] toByteArray() throws IOException {
        return value;
    }

    public static Filter parseFrom(final byte [] pbBytes) throws DeserializationException {
        return new CustomerFilter(pbBytes);
    }
}
